layui.use('laydate', function(){
    var laydate = layui.laydate;

    //常规用法
    laydate.render({
        elem: '#ggCContractTime',
        elem: '#ggCDueTime',
    });
})

// 上传文件
layui.use('upload', function(){
    var upload = layui.upload;
    //普通图片上传
    var uploadInst = upload.render({
        elem: '#ggCPploadInformation'
        ,url: '/contract/uploadContract'
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });
})

// 增加信息
function add_items_contract() {
    console.log('das')
    var ggCNumber = $("#ggCNumber").val() // 合同编号
    var ggCContractName = $("#ggCContractName").val() // 合同名字
    var ggCInstitutionalName = $("#ggCInstitutionalName").val() // 机构名字
    var ggCTypeOfContract = $("#ggCTypeOfContract").val() // 合同类型
    var ggCcontractAmount = $("#ggCcontractAmount").val() // 合同金额
    var ggCpersonInCharge = $("#ggCpersonInCharge").val() // 经办人
    var ggCAuditStatus = $("#ggCAuditStatus").val() // 审核状态
    var ggCContractTime = $("#ggCContractTime").val() //签约时间
    var ggCDueTime = $("#ggCDueTime").val() //到期时间
    var ggCNatureOfContract = $("#ggCNatureOfContract").val() //合同性质
    var ggCContractContact = $("#ggCContractContact").val() //合同联系人
    var ggCTotalContractAmount = $("#ggCTotalContractAmount").val() //合同总金额
    var ggCPaymentMethod = $("#ggCPaymentMethod").val() // 付款方式
    var ggCSignedBy = $("#ggCSignedBy").val() // 合同签字人
    var ggCContractSeal = $("#ggCContractSeal").val() // 合同盖章
    var ggCSignatureOfContract = $("#ggCSignatureOfContract").val() // 合同签盖章名字
    var ggCRemarks = $("#ggCRemarks").val() // 备注说明
    var ggCPploadInformation = $("#ggCPploadInformation").val() // 上传信息
    var ggCExpirationReminder = $("#ggCExpirationReminder").val() // 到期是否提醒

    $.ajax({
        type: "POST",
        url: "/contract/addContractItems",
        data:{
            ggCNumber: ggCNumber,
            ggCContractName: ggCContractName,
            ggCInstitutionalName: ggCInstitutionalName,
            ggCTypeOfContract: ggCTypeOfContract,
            ggCcontractAmount: ggCcontractAmount,
            ggCpersonInCharge: ggCpersonInCharge,
            ggCAuditStatus: ggCAuditStatus,
            ggCContractTime: ggCContractTime,
            ggCDueTime: ggCDueTime,
            ggCNatureOfContract: ggCNatureOfContract,
            ggCContractContact: ggCContractContact,
            ggCTotalContractAmount: ggCTotalContractAmount,
            ggCPaymentMethod: ggCPaymentMethod,
            ggCSignedBy: ggCSignedBy,
            ggCContractSeal: ggCContractSeal,
            ggCSignatureOfContract: ggCSignatureOfContract,
            ggCRemarks: ggCRemarks,
            ggCPploadInformation: "a",
            ggCExpirationReminder: ggCExpirationReminder,
        },
        success: function (message) {
            if(message.code==0){
                layer.msg('增加成功！');
            }else {
                layer.msg('增加失败！');
            }
        }
    })
}